package com.emm.yixun.website.controller.InterfaceData;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import com.emm.yixun.common.model.dto.*;
import com.emm.yixun.common.model.enums.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.emm.yixun.common.enums.ResponseEnums;
import com.emm.yixun.common.model.BusinessAbnorma;
import com.emm.yixun.common.model.Customer;
import com.emm.yixun.common.model.FamilyMember;
import com.emm.yixun.common.model.Image;
import com.emm.yixun.common.model.PriceScheme;
import com.emm.yixun.common.model.Project;
import com.emm.yixun.common.model.ProjectRoom;
import com.emm.yixun.common.model.SaleReturnPmo;
import com.emm.yixun.common.model.Subscribe;
import com.emm.yixun.common.model.SubscribeInfo;
import com.emm.yixun.common.model.User;
import com.emm.yixun.common.model.pmo.GraphicalVo;
import com.emm.yixun.common.model.pmo.PicHighchartsVo;
import com.emm.yixun.common.model.pmo.PmoReportDto;
import com.emm.yixun.common.response.Response;
import com.emm.yixun.common.response.ResponseList;
import com.emm.yixun.common.utils.DateStyle;
import com.emm.yixun.common.utils.DateUtils;
import com.emm.yixun.customer.service.CustomerServiceFacade;
import com.emm.yixun.customer.service.SubscribeServiceFacade;
import com.emm.yixun.estate.service.ProjectRoomServiceFacade;
import com.emm.yixun.estate.service.ProjectServiceFacade;
import com.emm.yixun.marketing.service.BusinessAbnormaServiceFacade;
import com.emm.yixun.marketing.service.PriceSchemeServiceFacade;
import com.emm.yixun.system.service.BusinessLogServiceFacade;
import com.emm.yixun.system.service.UserServiceFacade;
import com.emm.yixun.website.common.ajax.AjaxRes;
import com.emm.yixun.website.common.utils.base.Const;
import com.emm.yixun.website.common.utils.security.ShiroUtil;
import com.emm.yixun.website.controller.base.BaseController;
import com.emm.yixun.website.service.ActivitiProcessServiceImpl;
import com.emm.yixun.website.service.ao.DataService.OaDataService;
import com.emm.yixun.website.service.pmo.LevelProjectDataService;
import com.emm.yixun.website.vo.changeroom.SignedChangeVo;
import com.emm.yixun.website.vo.process.ProcessScheduleVo;

/**
 * 
 * @ClassName: WordFlowDataController
 * @Description: 流程数据接口，每个流程的审批单数据接口提供，H5,PC使用
 * @author Administrator
 * @date 2017年6月1日 上午11:37:46
 * @version 1.0
 */
@Controller
@RequestMapping(value = "wordFlowData")
public class WorkFlowDataController extends BaseController<Object> {
	@Autowired
	private ActivitiProcessServiceImpl activitiProcessServiceImpl;
	@Autowired
	private UserServiceFacade userServiceFacade;
	@Autowired
	private PriceSchemeServiceFacade priceSchemeServiceFacade;
	@Autowired
	private BusinessAbnormaServiceFacade businessAbnormaServiceFacade;
	@Autowired
	private OaDataService oaDataService;
	@Autowired
	private SubscribeServiceFacade subscribeServiceFacade;
	@Autowired
	private CustomerServiceFacade customerServiceFacade;
	@Autowired
	private ProjectRoomServiceFacade projectRoomServiceFacade;
	@Autowired
	private LevelProjectDataService levelProjectDataService;
	@Autowired
	private ProjectServiceFacade projectServiceFacade;
	@Autowired
	private BusinessLogServiceFacade businessLogServiceFacade;

	/**
	 * 价格方案流程审批数据
	 * 
	 * @param id
	 *            价格方案Id
	 * @return
	 */
	@RequestMapping("priceSchemeApplyInfo")
	public @ResponseBody AjaxRes priceSchemeApplyInfo(Long id) {
		AjaxRes ajaxRes = new AjaxRes();
		ajaxRes.setRes(Const.FAIL);
		try {
			Map<String, Object> objectMap = new HashMap<String, Object>();
			Response<PriceScheme> priceSchemeRes = priceSchemeServiceFacade.findById(id);
			if (priceSchemeRes.isSuccess()) {
				PriceScheme priceScheme = priceSchemeRes.getEntity();
				ValuationTypeEnum type = ValuationTypeEnum.getByNo(priceScheme.getValuationType());
				if (type != null) {
					priceScheme.setValuationType(type.getName());
				}
				String priceSchemeStr = JSON.toJSONString(priceScheme);
				JSONObject jsonObject = JSONObject.parseObject(priceSchemeStr);
				jsonObject.put("executionDate", "");
				if (null != priceScheme.getExecutionDate()) {
					jsonObject.put("executionDate",
							DateUtils.DateToString(priceScheme.getExecutionDate(), DateStyle.YYYY_MM_DD));
				}
				objectMap.put("priceScheme", jsonObject);
				ajaxRes.setRes(Const.SUCCEED);
				ajaxRes.setObj(objectMap);
			} else {
				ajaxRes.setResMsg("价格方案不存在!!!");
			}
		} catch (Exception ex) {
			ajaxRes.setResMsg("数据加载失败: " + ex.getMessage());
			ex.printStackTrace();
		}
		return ajaxRes;
	}

	/**
	 * 价格方案无效流程审批数据
	 * 
	 * @param id
	 *            价格方案异常流程Id
	 * @return
	 */
	@RequestMapping("priceSchemeInvalidInfo")
	public @ResponseBody AjaxRes priceSchemeInvalidInfo(Long id) {
		AjaxRes ajaxRes = new AjaxRes();
		ajaxRes.setRes(Const.FAIL);
		try {
			Map<String, Object> objectMap = new HashMap<String, Object>();
			// 异常流程信息
			Response<BusinessAbnorma> businessAbnormaResponse = businessAbnormaServiceFacade.findById(Long.valueOf(id));
			// 价格方案信息
			Response<PriceScheme> priceSchemeRes = priceSchemeServiceFacade
					.findById(Long.valueOf(businessAbnormaResponse.getEntity().getBusinessId()));
			if (priceSchemeRes.isSuccess() && null != priceSchemeRes.getEntity()) {
				// 价格方案
				PriceScheme priceScheme = priceSchemeRes.getEntity();
				priceScheme.setCreateTime(businessAbnormaResponse.getEntity().getCreateTime());
				User user = userServiceFacade.findById(businessAbnormaResponse.getEntity().getCreateUserId())
						.getEntity();
				priceScheme.setCreateCN(user.getUserName());
				ValuationTypeEnum type = ValuationTypeEnum.getByNo(priceScheme.getValuationType());
				if (type != null) {
					priceScheme.setValuationType(type.getName());
				}
				String priceSchemeStr = JSON.toJSONString(priceScheme);
				JSONObject jsonObject = JSONObject.parseObject(priceSchemeStr);
				// 无效原因
				jsonObject.put("invalidRemark", businessAbnormaResponse.getEntity().getRemark());
				jsonObject.put("executionDate", "");
				if (null != priceScheme.getExecutionDate()) {
					jsonObject.put("executionDate",
							DateUtils.DateToString(priceScheme.getExecutionDate(), DateStyle.YYYY_MM_DD));
				}
				objectMap.put("priceScheme", jsonObject);

				ajaxRes.setRes(Const.SUCCEED);
				ajaxRes.setObj(objectMap);
			} else {
				ajaxRes.setResMsg("价格方案不存在!!!");
				objectMap.put("priceScheme", new JSONObject().toJSONString());
			}
		} catch (Exception ex) {
			ajaxRes.setResMsg("数据加载失败: " + ex.getMessage());
			ex.printStackTrace();
		}
		return ajaxRes;
	}

	/**
	 * @Title: workFlowHistroy @Description: 流程审批历史记录 @param @param
	 *         processInstanceId @param @param userId @param @return 设定文件 @return
	 *         List<ProcessScheduleVo> 返回类型 @throws
	 */
	@RequestMapping(value = "workFlowHistroy")
	public @ResponseBody AjaxRes workFlowHistroy(String processInstanceId, Long userId) {
		AjaxRes ajaxRes = getAjaxRes();
		try {
			User user = userServiceFacade.findById(userId).getEntity();
			List<ProcessScheduleVo> list = activitiProcessServiceImpl.getProcessScheduleList(user.getMerchantId(),
					processInstanceId);
			ajaxRes.setObj(list);
			ajaxRes.setRes(Const.SUCCEED);
		} catch (Exception e) {
			ajaxRes.setRes(Const.FAIL);
			ajaxRes.setResMsg("系统异常");
		}
		return ajaxRes;
	}

	/**
	 *
	 * @Title: subscribeDiscount @Description: 认购折扣审批表单数据 @param @param id
	 *         认购Id @param @return 设定文件 @return Map<String,Object> 返回类型 @throws
	 */
	@RequestMapping(value = "subscribeDiscount")
	public @ResponseBody AjaxRes subscribeDiscount(Long id) {
		Map<String, Object> map = new HashMap<String, Object>();
		AjaxRes ajaxRes = getAjaxRes();
		try {
			Subscribe subscribe = subscribeServiceFacade.findById(id).getEntity();

			JSONObject estateRecord = oaDataService.getEstateRecord(subscribe.getRoomId());
			estateRecord.put("calculateArea", subscribe.getCalculateArea()); // 计价面积
			estateRecord.put("unitPrice", subscribe.getConversionPrice()); // 折前单价
			estateRecord.put("totalPrice", subscribe.getLumpsumPrice()); // 折前总价
			JSONObject customerRecord = oaDataService.getCustomerRecord(subscribe.getCustomerId());
			map.put("customerRecord", customerRecord);
			map.put("estateRecord", estateRecord);

			FamilyMemberDto familyMemberDto = new FamilyMemberDto();
			familyMemberDto.setBuyId(id);
			familyMemberDto.setMemberType(MemberTypeEnum.SUBSCRIBE.getNo());
			map.put("subscribeRecord", oaDataService.getsubscribeRecord(id));
			ajaxRes.setObj(map);
			ajaxRes.setRes(Const.SUCCEED);
		} catch (Exception e) {
			ajaxRes.setRes(Const.FAIL);
			ajaxRes.setResMsg("系统异常");
		}
		return ajaxRes;
	}

	/**
	 *
	 * @Title: subscribeRetreat @Description: 认购退房审批表单数据 @param @param id
	 *         异常流程Id @param @return 设定文件 @return Map<String,Object> 返回类型 @throws
	 */
	@RequestMapping(value = "subscribeRetreat")
	public @ResponseBody AjaxRes subscribeRetreat(Long id) {
		Map<String, Object> map = new HashMap<String, Object>();
		AjaxRes ajaxRes = getAjaxRes();
		ajaxRes.setRes(Const.FAIL);
		try {
			Response<BusinessAbnorma> baRes = businessAbnormaServiceFacade.findById(Long.valueOf(id));
			if (baRes.isSuccess()) {
				BusinessAbnorma ba = baRes.getEntity();
				map.put("subscribeId", ba.getBusinessId());
				map.put("businessAbnormaId", id);
				map.put("auditStatus", ba.getAuditStatus());
				map.put("procInstId", ba.getProcInstId());
				User userFlow = userServiceFacade.findById(ba.getCreateUserId()).getEntity();
				map.put("userActName", userFlow.getUserName());
				// 退认购详情
				Response<SubscribeInfo> response = subscribeServiceFacade.findByIdInfo(ba.getBusinessId());
				if (response.isSuccess() && null != response.getEntity()) {
					SubscribeInfo subscribe = response.getEntity();
					String subscribeStr = JSON.toJSONString(subscribe);
					JSONObject data = JSONObject.parseObject(subscribeStr);
					// 认购转签约日期
					Date conversionSignDate = subscribe.getConversionSignDate();
					data.put("conversionSignDate", "");
					if (null != conversionSignDate) {
						data.put("conversionSignDate",
								DateUtils.DateToString(conversionSignDate, DateStyle.YYYY_MM_DD));
					}
					// 客户名称
					data.put("customerName", "");
					Response<Customer> customerResponse = customerServiceFacade.findById(subscribe.getCustomerId());
					if (customerResponse.isSuccess() && null != customerResponse.getEntity()) {
						data.put("customerName", customerResponse.getEntity().getCustomerName());
					}

					// 房号
					data.put("propertyTypeName", "");
					data.put("roomName", "");
					Response<ProjectRoom> projectRoomResponse = projectRoomServiceFacade
							.findById(subscribe.getRoomId());
					if (projectRoomResponse.isSuccess() && null != projectRoomResponse.getEntity()) {
						data.put("roomName", projectRoomResponse.getEntity().getCombinedName());
						String propertyType = projectRoomResponse.getEntity().getPropertyType();
						if (StringUtils.isNotBlank(propertyType)) {
							data.put("propertyTypeName", PropertyTypeEnum.getByNo(propertyType).getDes());
						}
					}
					data.put("agentName", subscribe.getUserName());
					data.put("remark", ba.getRemark());
					if (StringUtils.isNotBlank(String.valueOf(id))) {
						data.put("tcCreateTime", "");
						data.put("delayDate", "");
						if (null != ba.getConversionSignDate() && null != ba.getDelaydate()) {
							long subDay = DateUtils.getDaysSub(ba.getConversionSignDate(), ba.getDelaydate());
							data.put("delayShowDay", subDay + "天");
						}
						data.put("tcCreateTime", DateUtils.formatDate(ba.getCreateTime(), null));
						if (null != ba.getDelaydate()) {
							data.put("delayDate", DateUtils.formatDate(ba.getDelaydate(), null));
						}
					}
					map.put("subRetreat", data);
				} else {
					ajaxRes.setResMsg("退认购信息不存在!!!");
					map.put("subRetreat", new JSONObject().toJSONString());
				}
			} else {
				ajaxRes.setResMsg("退认购信息不存在!!!");
				map.put("subRetreat", new JSONObject().toJSONString());
			}
			ajaxRes.setObj(map);
			ajaxRes.setRes(Const.SUCCEED);
		} catch (Exception e) {
			ajaxRes.setRes(Const.FAIL);
			ajaxRes.setResMsg("数据加载失败: " + e);
		}
		return ajaxRes;
	}

	/**
	 *
	 * @Title: subscribeRoomChange @Description: 认购换房审批表单数据 @param @param id
	 *         异常流程Id @param @return 设定文件 @return Map<String,Object> 返回类型 @throws
	 */
	@RequestMapping(value = "subscribeRoomChange")
	public @ResponseBody AjaxRes subscribeRoomChange(Long id) {
		Map<String, Object> map = new HashMap<String, Object>();
		AjaxRes ajaxRes = getAjaxRes();
		ajaxRes.setRes(Const.FAIL);
		try {
			AbnormaBusinessView abView = businessAbnormaServiceFacade.findAbormaBusinessDetailById(id);
			map.put("subscribeRoomChange", abView);
			ajaxRes.setObj(map);
			ajaxRes.setRes(Const.SUCCEED);
		} catch (Exception e) {
			ajaxRes.setRes(Const.FAIL);
			ajaxRes.setResMsg("数据加载失败: " + e);
		}
		return ajaxRes;
	}

	/**
	 *
	 * @Title: changeName @Description: 认购、签约更名审批表单数据 @param @param id
	 *         异常流程Id @param @return 设定文件 @return Map<String,Object> 返回类型 @throws
	 */
	@RequestMapping(value = "changeName")
	public @ResponseBody AjaxRes changeName(Long id) {
		Map<String, Object> map = new HashMap<String, Object>();
		AjaxRes ajaxRes = getAjaxRes();
		ajaxRes.setRes(Const.FAIL);
		try {
			// 换房信息
			map.put("changeNameInfo", new JSONObject().toJSONString());
			// 原客户信息
			map.put("fmOldList", "");
			// 新客户信息
			map.put("fmNewList", "");
			// 愿共同购房者
			map.put("fmOldTogetherList", "");
			// 新共同购房者
			map.put("fmNewTogetherList", "");
			Response<BusinessAbnorma> baRes = businessAbnormaServiceFacade.findById(Long.valueOf(id));
			if (baRes.isSuccess()) {
				BusinessAbnorma ba = baRes.getEntity();
				String abnormaId = String.valueOf(ba.getId());
				// 认购、签约业务Id
				Long businessId = ba.getBusinessId();
				// 业务类型,对应BusinessAbnormaEnum
				String businessType = ba.getBusinessType();
				map.put("businessType", businessType);
				if (BusinessAbnormaEnum.BusinessAbnorma_11.getNo().equals(businessType)) {
					JSONObject jsonObject = oaDataService.loadSubChangeNameInfo(businessId, abnormaId);

					map.put("changeNameInfo", jsonObject);
					// 认购新共同购房者
					FamilyMemberDto fmDto = new FamilyMemberDto();
					fmDto.setMemberType(MemberTypeEnum.SUBSCRIBECHANGENAME.getNo());
					fmDto.setBuyId(Long.valueOf(abnormaId));
					List<FamilyMember> fmList = oaDataService.getFamilyMember(fmDto);
					map.put("fmNewTogetherList", fmList);
				} else if (BusinessAbnormaEnum.BusinessAbnorma_6.getNo().equals(businessType)) {
					JSONObject jsonObject = oaDataService.loadSignedChangeNameInfo(businessId, abnormaId);
					map.put("changeNameInfo", jsonObject);
					// 签约新共同购房者
					FamilyMemberDto fmDto = new FamilyMemberDto();
					fmDto.setMemberType(MemberTypeEnum.SIGNEDCHANGENAME.getNo());
					fmDto.setBuyId(Long.valueOf(abnormaId));
					List<FamilyMember> fmList = oaDataService.getFamilyMember(fmDto);
					map.put("fmNewTogetherList", fmList);
				}

				FamilyMemberDto fmDto = new FamilyMemberDto();
				// 认购、签约原客户信息
				fmDto = new FamilyMemberDto();
				fmDto.setMemberType(MemberTypeEnum.Y_CUSTOMER_INFO.getNo());
				fmDto.setBuyId(Long.valueOf(abnormaId));
				List<FamilyMember> fmList = oaDataService.getFamilyMember(fmDto);
				map.put("fmOldList", fmList);

				// 认购、签约新客户信息
				fmDto = new FamilyMemberDto();
				fmDto.setMemberType(MemberTypeEnum.N_CUSTOMER_INFO.getNo());
				fmDto.setBuyId(Long.valueOf(abnormaId));
				fmList = oaDataService.getFamilyMember(fmDto);
				map.put("fmNewList", fmList);

				// 认购、签约原共同购房者信息
				fmDto = new FamilyMemberDto();
				fmDto.setMemberType(MemberTypeEnum.Y_COMMON_INFO.getNo());
				fmDto.setBuyId(Long.valueOf(abnormaId));
				fmList = oaDataService.getFamilyMember(fmDto);
				map.put("fmOldTogetherList", fmList);
				ajaxRes.setObj(map);
				ajaxRes.setRes(Const.SUCCEED);
			} else {
				ajaxRes.setResMsg("更名信息不存在!!!");
			}

		} catch (Exception e) {
			ajaxRes.setRes(Const.FAIL);
			ajaxRes.setResMsg("数据加载失败: " + e);
		}
		return ajaxRes;
	}

	/**
	 * 延期签约流程 包含15天内,15-30天、30天以上 @Title: subDelaySigned @Description:
	 * 延期签约审批表单数据 @param @param id 异常流程Id @param @return 设定文件 @return
	 * Map<String,Object> 返回类型 @throws
	 */
	@RequestMapping(value = "subDelaySigned")
	public @ResponseBody AjaxRes subDelaySigned(Long id) {
		Map<String, Object> map = new HashMap<String, Object>();
		AjaxRes ajaxRes = getAjaxRes();
		ajaxRes.setRes(Const.FAIL);
		try {
			map.put("delayInfo", "");
			Response<BusinessAbnorma> baRes = businessAbnormaServiceFacade.findById(id);
			if (baRes.isSuccess()) {
				BusinessAbnorma ba = baRes.getEntity();
				Long subscribeId = ba.getBusinessId();
				JSONObject jsonObject = oaDataService.loadSubDelaySigned(subscribeId, String.valueOf(id));
				map.put("delayInfo", jsonObject);
				ajaxRes.setObj(map);
				ajaxRes.setRes(Const.SUCCEED);
			} else {
				ajaxRes.setResMsg("延期签约信息不存在!!!");
			}
		} catch (Exception e) {
			ajaxRes.setRes(Const.FAIL);
			ajaxRes.setResMsg("数据加载失败: " + e);
		}
		return ajaxRes;
	}

	/**
	 *
	 * @Title: signedDiscount @Description: 签约折扣审批表单数据 @param @param id
	 *         异常流程Id @param @return 设定文件 @return Map<String,Object> 返回类型 @throws
	 */
	@RequestMapping(value = "signedDiscount")
	public @ResponseBody AjaxRes signedDiscount(Long id) {
		Map<String, Object> map = new HashMap<String, Object>();
		AjaxRes ajaxRes = getAjaxRes();
		ajaxRes.setRes(Const.FAIL);
		try {
			map = oaDataService.loadSignedInfo(id);
			ajaxRes.setObj(map);
			ajaxRes.setRes(Const.SUCCEED);
		} catch (Exception e) {
			ajaxRes.setRes(Const.FAIL);
			ajaxRes.setResMsg("数据加载失败: " + e);
		}
		return ajaxRes;
	}

	/**
	 *
	 * @Title: signedChangeRoom @Description: 签约換房审批表单数据 @param @param signedId
	 *         签约Id @param @return 设定文件 @return Map<String,Object> 返回类型 @throws
	 */
	@RequestMapping(value = "signedChangeRoom")
	public @ResponseBody AjaxRes signedChangeRoom(Long signedId) {
		Map<String, Object> map = new HashMap<String, Object>();
		AjaxRes ajaxRes = getAjaxRes();
		ajaxRes.setRes(Const.FAIL);
		try {
			SignedChangeVo signedChangeVo = oaDataService.loadSignedChangeRoomInfo(signedId);
			map.put("signedChangeRoomInfo", signedChangeVo);
			ajaxRes.setObj(map);
			ajaxRes.setRes(Const.SUCCEED);
		} catch (Exception e) {
			ajaxRes.setRes(Const.FAIL);
			ajaxRes.setResMsg("数据加载失败: " + e);
		}
		return ajaxRes;
	}

	/**
	 *
	 * @Title: signedCheckOut @Description: 签约退房表单数据 @param @param id
	 *         异常流程Id @param @return 设定文件 @return Map<String,Object> 返回类型 @throws
	 */
	@RequestMapping(value = "signedCheckOut")
	public @ResponseBody AjaxRes signedCheckOut(Long id) {
		Map<String, Object> map = new HashMap<String, Object>();
		AjaxRes ajaxRes = getAjaxRes();
		ajaxRes.setRes(Const.FAIL);
		try {
			JSONObject jsonObject = new JSONObject();
			// 退房异常信息
			Response<BusinessAbnorma> baRes = businessAbnormaServiceFacade.findById(id);
			if (baRes.isSuccess()) {
				BusinessAbnorma ba = baRes.getEntity();
				// 退房流程表单数据
				jsonObject = oaDataService.loadSignedChangeNameInfo(ba.getBusinessId(), String.valueOf(id));
			}
			map.put("signedCheckOutInfo", jsonObject);
			ajaxRes.setObj(map);
			ajaxRes.setRes(Const.SUCCEED);
		} catch (Exception e) {
			ajaxRes.setRes(Const.FAIL);
			ajaxRes.setResMsg("数据加载失败: " + e);
		}
		return ajaxRes;
	}

	/**
	 *
	 * @Title: loadDeferredPaymentDetail @Description: 应收款延期表单数据 @param @param id
	 *         异常流程Id @param @return 设定文件 @return Map<String,Object> 返回类型 @throws
	 */
	@RequestMapping(value = "loadDeferredPaymentDetail")
	public @ResponseBody AjaxRes loadDeferredPaymentDetail(Long id) {
		Map<String, Object> map = new HashMap<String, Object>();
		AjaxRes ajaxRes = getAjaxRes();
		ajaxRes.setRes(Const.FAIL);
		try {
			JSONObject jsonObject = new JSONObject();
			jsonObject = oaDataService.loadDeferredPaymentDetail(id);
			map.put("deferredPayment", jsonObject);
			ajaxRes.setObj(map);
			ajaxRes.setRes(Const.SUCCEED);
		} catch (Exception e) {
			ajaxRes.setRes(Const.FAIL);
			ajaxRes.setResMsg("数据加载失败: " + e);
		}
		return ajaxRes;
	}

	/**
	 * 
	 * queryProcessImages:(查询流程附件). <br/>
	 *
	 * @author Administrator
	 * @param objectId
	 * @param imageType
	 * @return
	 * @since JDK 1.6
	 */
	@RequestMapping(value = "queryProcessImages")
	@ResponseBody
	public List<Image> queryProcessImages(String objectId, String imageType) {
		User user = ShiroUtil.getCurrentUser();
		Long merchantId = null;
		if (null != user) {
			merchantId = user.getMerchantId();
		}
		return oaDataService.queryProcessImages(objectId, imageType, merchantId);
	}

	/**
	 * 
	 * processCheck:流程审核 <br/>
	 *
	 * @author Administrator
	 * @param taskId
	 * @param checkStatus
	 * @param message
	 * @param userId
	 * @return
	 * @since JDK 1.6
	 */
	@RequestMapping(value = "processCheck")
	public @ResponseBody AjaxRes processCheck(String taskId, String checkStatus, String message, Long userId) {
		AjaxRes ar = new AjaxRes();
		User user = ShiroUtil.getCurrentUser();
		try {
			ar = oaDataService.processCheck(taskId, checkStatus, message, userId);
		} catch (Exception ex) {
			if(ex.getMessage().contains(ResponseEnums.RESPONSEENUMS_999999.getName())) {
				ar.setResMsg(ResponseEnums.RESPONSEENUMS_999999.getName());
				ar.setRes(Const.OTHER);
			}else {
				ar.setFailMsg("审核失败");
			}
			logger.error("OA审批失败", ex);
			//新增业务操作异常记录
			businessLogServiceFacade.saveExceptionLog(user, "OA审批失败", taskId+"|"+checkStatus+"|"+message, JSONObject.toJSONString(ex));
		}
		return ar;
	}

	/**
	 * 
	 * familyMemberList:(查询共同购房者). <br/>
	 *
	 * @author Administrator
	 * @param buyId
	 * @param memberType
	 * @return
	 * @since JDK 1.6
	 */
	@RequestMapping(value = "familyMemberList")
	public @ResponseBody List<FamilyMember> familyMemberList(Long buyId, String memberType) {
		FamilyMemberDto dto = new FamilyMemberDto();
		dto.setBuyId(buyId);
		dto.setMemberType(memberType);
		return oaDataService.getFamilyMember(dto);
	}

	/**
	 * 
	 * getWorkFlowName:获得流程名称，设置页面标题. <br/>
	 * 
	 * @author Administrator
	 * @param processId
	 * @return
	 * @since JDK 1.6
	 */
	@RequestMapping(value = "getWorkFlowName")
	public @ResponseBody AjaxRes getWorkFlowName(String processId) {
		AjaxRes res = getAjaxRes();
		res.setObj(oaDataService.getWorkFlowName(processId));
		return res;
	}

	/**
	 * 
	 * queryContactWary:微信端跟进统计. <br/>
	 *
	 * @author Administrator
	 * @param index
	 * @return
	 * @since JDK 1.6
	 */
	@RequestMapping("/queryContactWary")
	public @ResponseBody Map<String, Object> queryContactWary(String index, HttpServletResponse response, String userId,
			String userticket) throws IOException {
		HashMap<String, String> hashMap = oaDataService.getOaId(userId, userticket);
		Map<String, Object> maps = new HashMap<String, Object>();
		if (hashMap == null) {
			maps.put("error", "获取用户失败");
		} else if (!StringUtils.isEmpty(hashMap.get("error"))) {
			maps.put("error", hashMap.get("error"));
		} else if (!StringUtils.isEmpty(hashMap.get("oaId"))) {
			String oaId = hashMap.get("oaId");
			Map<String, String> map = com.emm.yixun.website.utils.ContactWayUtils.getDate(index);
			String startTime = map.get("createStartDate");
			String endDate = map.get("endDate");
			ResponseList<ContactWayDto> responseList = customerServiceFacade.queryProjectFtContactWay(startTime,
					endDate, oaId);
			ResponseList<HighchartsDto> higResponseList = customerServiceFacade
					.queryCustomerLevel(responseList.getEntity(), startTime, endDate);
			maps.put("contactWay", responseList.getEntity());
			maps.put("highcharts", higResponseList.getEntity());
		}
		return maps;

	}

	/**
	 * 
	 * @param userticket
	 * @return
	 */
	@RequestMapping(value = "getUser")
	public @ResponseBody AjaxRes getUser(String userticket) {
		AjaxRes ar = getAjaxRes();
		HashMap<String, String> map = oaDataService.getUser(userticket);
		//map.put("oaId", "DF0106101");
		String value = map.get("oaId");
		if (map != null && !map.isEmpty() && !StringUtils.isEmpty(value)) {
			ar.setRes(Const.SUCCEED);
			ar.setResMsg(value);
		} else {
			ar.setRes(Const.FAIL);
			ar.setResMsg(map.get("error"));
		}
		return ar;
	}

	/**
	 * 
	 * queryProjectSignedInfo:微信签约报表. <br/>
	 *
	 * @author Administrator
	 * @param index
	 * @return
	 * @since JDK 1.6
	 */
	@RequestMapping("/queryProjectSignedInfo")
	public @ResponseBody ResponseList<SalesReportAppDto> queryProjectSignedInfo(String index, String userId,
			String userticket) {
		ResponseList<SalesReportAppDto> responseList = new ResponseList<SalesReportAppDto>();
		HashMap<String, String> hashMap = oaDataService.getOaId(userId, userticket);
		if (hashMap == null) {
			responseList.setSuccess(false);
			responseList.setResultMessage("获取用户失败");
		} else if (!StringUtils.isEmpty(hashMap.get("error"))) {
			responseList.setSuccess(false);
			responseList.setResultMessage(hashMap.get("error"));
		} else if (!StringUtils.isEmpty(hashMap.get("oaId"))) {
			Map<String, String> map = com.emm.yixun.website.utils.ContactWayUtils.getDate(index);
			String startTime = map.get("createStartDate");
			String endDate = map.get("endDate");
			String oaId = hashMap.get("oaId");
			ResponseList<SalesReportAppDto> result = customerServiceFacade.queryProjectSignedInfo(startTime, endDate,
					oaId);
			responseList.setSuccess(true);
			responseList.setEntity(result.getEntity());
		}
		return responseList;
	}

	/**
	 * findPmoInfo:(PMO某一年的动态数据). <br/>
	 * 
	 * @author Administrator
	 * @param projectId
	 * @param year
	 * @return
	 * @since JDK 1.6
	 */
	@RequestMapping("/findPmoInfo")
	public @ResponseBody HashMap<String, List<GraphicalVo<Double>>> findPmoInfo(Long projectId, String year) {
		HashMap<String, List<GraphicalVo<Double>>> map = new HashMap<String, List<GraphicalVo<Double>>>();
		try {
			map = levelProjectDataService.findDynamiSalesData(projectId, year);
		} catch (Exception e) {
			logger.error("error pmo:", e);
		}
		return map;
	}

	/**
	 * 
	 * findProjectPlan:(销售计划). <br/>
	 * 
	 * @author Administrator
	 * @param projectId
	 * @return
	 * @since JDK 1.6
	 */
	@RequestMapping("/findProjectPlan")
	public @ResponseBody List<GraphicalVo<Double>> findProjectPlan(Long projectId, String saleReturnFlag, String year) {
		// 销售计划
		List<GraphicalVo<Double>> vo = new ArrayList<GraphicalVo<Double>>();
		try {
			ResponseList<SaleReturnPmo> responseSaleList = new ResponseList<SaleReturnPmo>();
			if (saleReturnFlag.equals(SaleReturnEnum.SALE.getNo())) {
				responseSaleList = projectServiceFacade.querySaleReturnListPmo(projectId, null, SaleReturnEnum.SALE, year);
				String[] title = new String[] { "计划销售额", "实际销售额" };
				vo = levelProjectDataService.findSaleData(responseSaleList.getEntity(), true, title);
			} else {
				responseSaleList = projectServiceFacade.querySaleReturnListPmo(projectId, null, SaleReturnEnum.RETURN, year);
				String[] title = new String[] { "计划回款额", "实际回款额" };
				vo = levelProjectDataService.findSaleData(responseSaleList.getEntity(), true, title);
			}
		}catch(Exception ex) {
			logger.error("获取计划销售、回款额失败", ex);
		}
		return vo;
	}

	/**
	 * 
	 * findProjectList:(绿城项目). <br/>
	 * 绿城工作流H5页面专用
	 * @author Administrator
	 * @return
	 * @since JDK 1.6
	 */
	@RequestMapping(value = "findProjectList")
	public @ResponseBody List<Project> findProjectList(ProjectDto dto) {
		dto.setDelFlag("0");
		// 项目数据权限资源缓存
		String resourcesCode = ShiroUtil.getDataPermissionResources(dto.getResourcesName());
		if (null == dto.getResourcesCode() || "".equals(dto.getResourcesCode())) {
			dto.setResourcesCode(resourcesCode);
		} else if ("".equals(resourcesCode)) {
			ShiroUtil.setDataPermissionResources(dto.getResourcesName(), dto.getResourcesCode());
		}
		dto.setMerchantId(Long.valueOf(MerchantEnum.GREEN_TOWN.getNo()));
		ResponseList<Project> projectList = projectServiceFacade.findByDto(dto);
		return projectList.getEntity();
	}

	/**
	 * 
	 * findIndustData:(业态数量统计). <br/>
	 * 
	 * @author Administrator
	 * @param projectId
	 * @return
	 * @since JDK 1.6
	 */
	@RequestMapping(value = "findIndustData")
	public @ResponseBody GraphicalVo<PicHighchartsVo> findIndustData(Long projectId) {
		return projectRoomServiceFacade.findIndustData(projectId);
	}

	/**
	 * 
	 * findIndustSalasData:(项目某年所有月份每个业态的销售). <br/>
	 * 
	 * @author Administrator
	 * @param projectId
	 * @param year
	 * @return
	 * @since JDK 1.6
	 */
	@RequestMapping(value = "findIndustSalasData")
	public @ResponseBody PmoReportDto findIndustSalasData(Long projectId, String year) {
		Response<PmoReportDto> responseList = projectServiceFacade.findIndustSalesData(projectId, year);
		return responseList.getEntity();
	}

}
